﻿using NLog;
using System;

public class LoggerHelp
{
    private static readonly NLog.Logger loginfo = LogManager.GetLogger("loginfo");
    private static readonly NLog.Logger logerror = LogManager.GetLogger("logerror");
    private static readonly NLog.Logger logmqtt = LogManager.GetLogger("logmqtt");

    private static readonly NLog.Logger logsInfo = LogManager.GetLogger("logsInfo");
    private static readonly NLog.Logger logsMEStIME = LogManager.GetLogger("logsMEStIME");
    private static readonly NLog.Logger logsSql = LogManager.GetLogger("logsSql");
    private static readonly NLog.Logger logsSysErrorLog = LogManager.GetLogger("logsSysErrorLog");
    private static readonly NLog.Logger logsSysErrorLogcn = LogManager.GetLogger("logsSysErrorLogcn");


    public static void WriteInfo(string info) => loginfo.Info(info);


    public static void WriteMqtt(string info) => logmqtt.Info(info);

    public static void WriteError(string error) => logerror.Info(error);

    public static void WriteError(string info, Exception ex) => logerror.Error(info, ex);


    public static void WriteEX(Exception ex) => logsSysErrorLog.Error(ex.Message + "\r\n" + ex.InnerException + "\r\n" + ex.StackTrace + "\r\n" + ex.Source, "SysErrorLog");

    public static void WriteEX(string ErrorName, Exception ex)
    {
        logsSysErrorLog.Error(ErrorName + "\r\n" + ex.Message + "\r\n" + ex.InnerException + "\r\n" + ex.StackTrace + "\r\n" + ex.Source, "SysErrorLog");
    }

    /// <summary>
    /// 写日志文件数据库日志文件
    /// </summary>
    /// <param name="message">消息</param>  
    public static void WriteLog(string message)
    {
        // logsInfo.IsInfoEnabled = true; 
        logsInfo.Info(message);
    }

    /// <summary>
    /// 写日志文件数据库日志文件
    /// </summary>
    /// <param name="message">消息</param> 
    /// <param name="direName">日志存储目录名称</param>
    public static void WriteLog(string message, string direName)
    {
        switch (direName)
        {
            case "Info":
                logsInfo.Info(message, "Info");
                break;
            case "SysErrorLog":
                logsSysErrorLog.Info(message, "SysErrorLog");
                break;
            case "SQL执行":
                logsSql.Info(message);
                break;
            case "MESTime":
                logsMEStIME.Info(message, "MESTime");
                break;
            case "系统报错":
                logsSysErrorLogcn.Info(message, "系统报错");
                break;
            default:
                break;
        }
    }
}

